package Controller;
import java.util.Date;

import client.ClientConsole;

import Entity.*;

import Entity.Customer;
import Entity.CasualSubscription;

import Entity.Complaint;
import Entity.ComplaintReport;
import Entity.DisabledPlace;
import Entity.DisabledReport;
import Entity.FullSubscription;
import Entity.OneTimeCostumerOrder;
import Entity.Order;
import Entity.OrderReport;
import Entity.Prices;
import Entity.Request;
import Entity.Worker.Role;
import GUI.FrameIS;
import GUI.FrameSystem;

/**
 * this is the DB controller. we have here a lot of function that we will use from the DB.
 * @author all of us
 *
 */
public class DBcontroller 
{
	private static ClientConsole c;
	public DBcontroller(ClientConsole cli) 
	{
		DBcontroller.c=cli;
	}
	
	public static Customer[] getCustomers(){return c.getCustomers();} 
	public static FullSubscription [] getFullSubscriptions() {return c.getFullSubscriptions();} 
	public static CasualSubscription [] getCasualSubscriptions() {return c.getCasualSubscriptions();}
	public static int getNumOfOrders(Date start,Date end,int pl) {return c.getCompleteOrder(start, end, pl);}
	public static int getNumOfSubsOrders(Date start,Date end,int pl) {return c.getCompleteOrder(start, end, pl);}
	public static int getNumOfInAdvance(Date start,Date end,int pl) {return 1;}
	public static DisabledPlace[] getNumOfDisabled(Date start,Date end,int pl) {DisabledPlace[] pr=new DisabledPlace[1]; return pr;}
	//************************* moran added those functions:
	// function for entities
	public static void saveComplaintToDB(Complaint complaint) {c.saveComplaintToDB(complaint);} // moran add this. this function will save the complaint to the DB (customer and worker will use this)
	public static void savePricesToDB(Prices prices){c.savePricesToDB(prices);} // moran add this. the parking lot manager will save the request to the DB if approved (company manager will use this)
	public static void saveRequestToDB(Request r){c.saveRequestToDB(r);} // moran add this. the parking lot manager will save the request to the DB (parking lot manager will use this)
	// function for tables in gui
	public static Complaint[] viewCustomerComplaintSQL(String cid){return c.viewCustomerComplaintSQL(cid);} // moran add this. this function will make a SQL query so the customer can see his complaints.
	public static void viewWorkerComplaintSQL(String id){c.viewWorkerComplaintSQL(id);} // moran add this. this function will make a SQL query so the worker can see resulted complaints.
	public static Request[] viewRequestsSQL(){return c.viewRequestsSQL();} // moran add this. this function will make a SQL query so the company manager can see the requests of every parking lot and approve/deny it.
	public static void deleteRequestSQL(int parkinglotnum, Date date){c.deleteRequestSQL(parkinglotnum, date);} // moran add this. this function will make a SQL query for deleting the request from the DB only if the approveflag is true(because the request table is temporary but dynamic)/
	// generic function for all of us
	public static String getLoggedIn(){return FrameSystem.getLoggedIn();} // moran add this. this function will return us the id of the one who logged in.
	public static int getCurrentParkingLotNum(){return FrameIS.getParkingLot();} // moran add this. this function will return us the parking lot number (will be used for parking lot worker for example)
	public static Prices getCurrentPrices(int parkinglotnum){return c.getCurrentPrices(parkinglotnum);} // moran add this. the company manager will watch the "old prices" by this function.
	//*********************************


	public static Complaint[] getComplaints(Date start,Date end) {return c.getComplaints(start, end);}
	public static Order[] getOrders() {return c.getOrders();}
	public static int getCompleteOrder(Date s,Date e,int parkingLot) {return c.getCompleteOrder(s, e, parkingLot);}
	public static int getUnCompleteOrder(Date s,Date e,int parkingLot) {return c.getUnCompleteOrder(s, e, parkingLot);}
	public static Order[] getLateness(int parkingLot){return c.getLateness(parkingLot);}
	public static int getNumOfCanceled(int p){return c.getNumOfCanceled(p);}
	public static OrderReport[] getOrderReports() {return c.getOrderReports();}
	public static ComplaintReport[] getComplaintReports() {return c.getComplaintReports();}
	public static DisabledReport[] getDisabledReports() {return c.getDisabledReports();}

	public static ParkingLot[] getParkingLots_sorted()	//parking lots are sorted by parking lot number(parking lot i is at [i-1])
	{
		ParkingLot[] plots=new ParkingLot[6];
		plots[0]=new ParkingLot();
		plots[0].setParking_lot_number(0);
		plots[0].setParking_lot_name("ramatgan");
		plots[0].createParkingLot(3, 3, 4);
		
		plots[1]=new ParkingLot();
		plots[1].setParking_lot_number(1);
		plots[1].setParking_lot_name("givataim");
		plots[1].createParkingLot(3, 3, 4);
		plots[2]=new ParkingLot();
		plots[2].setParking_lot_number(2);
		plots[2].setParking_lot_name("telaviv");
		plots[2].createParkingLot(3, 3, 4);
		plots[3]=new ParkingLot();
		plots[3].setParking_lot_number(3);
		plots[3].setParking_lot_name("natania");
		plots[3].createParkingLot(3, 3, 4);
		plots[4]=new ParkingLot();
		plots[4].setParking_lot_number(4);
		plots[4].setParking_lot_name("haifa");
		plots[4].createParkingLot(3, 3, 4);
		plots[5]=new ParkingLot();
		plots[5].setParking_lot_number(5);
		plots[5].setParking_lot_name("beersheva");
		plots[5].createParkingLot(3, 3, 4);
		
		Date d=new Date();
		plots[0].insertCar("1111111", d);
		plots[0].insertCar("2222222", d);
		plots[0].insertCar("3333333", d);
		plots[0].insertCar("4444444", d);
		plots[0].insertCar("5555555", d);
		plots[0].insertCar("6666666", d);
		plots[0].insertCar("7777777", d);
		plots[0].insertCar("8888888", d);
		plots[0].insertCar("9999999", d);
		plots[0].insertCar("1234568", d);
		plots[0].insertCar("1234569", d);
		plots[0].insertCar("1234560", d);
		return plots;
	}

	public static int getNumOfSubs(int parkinglot) {return c.getNumOfSubs(parkinglot);}
	public static int getNumOfSubsWithMoreThen1Car(int parkinglot) {return c.getNumOfSubsWithMoreThen1Car(parkinglot);}
	public static Worker[] getWorkers() {return c.getWorkers();}

	public static void saveOrderReport(OrderReport r) {
		c.saveOrderReport(r);
	}

	public static void saveComplaintReport(ComplaintReport r) {
		c.saveComplaintReport(r);
	}

	public static void saveDisabledReport(DisabledReport r) {
		c.saveDisabledReport(r);
	}
	
	public static void deleteOrder(Order o)
	{
		c.deleteOrder(o);
	}

	public static OneTimeCostumerOrder[] getOneTimeCustomerOrder() {
		return c.getOneTimeCustomerOrder();
	}

	public static DisabledPlace getCurrectDisabledParkingSpot(int[] place,int parkingLot) {
		return c.getCurrectDisabledParkingSpot(place, parkingLot);
	}

	public static int getParkingLotOfWorker(String id) 
	{
		return c.getParkingLotOfWorker(id);
	}

	public static void saveOrder(Order order) {
		c.saveOrder(order);
	}

	public static void saveOneTimeCustomerOrder(OneTimeCostumerOrder order) {
		c.saveOneTimeCustomerOrder(order);
	}

	public static void deleteOneTimeCustomerOrder(
			OneTimeCostumerOrder oneTimeCostumerOrder) {
		c.deleteOneTimeCustomerOrder(oneTimeCostumerOrder);
		
	}

	public static void saveFullSub(FullSubscription sub) 
	{
		c.saveFullSub(sub);
	}

	public static void saveCasualSub(CasualSubscription sub) {
		c.saveCasualSub(sub);
	}
	
	public static void deleteFullSub(FullSubscription sub) 
	{
		c.deleteFullSub(sub);
	}
	
	public static void deleteCasualSub(CasualSubscription sub) 
	{
		c.deleteCasualSub(sub);
	}

	public static void saveDisabledPlace(DisabledPlace dp) 
	{
		c.saveDisabledPlace(dp);
	}
	
	public static void deleteDisabledPlace(DisabledPlace dp) 
	{
		c.deleteDisabledPlace(dp);
	}

	public static void deleteCustomer(Customer c2) {
		c.deleteCustomer(c2);
	}
	
	public static void saveCustomer(Customer r)
	{
		c.saveCustomer(r);
	}
	
	
}